package com.agent.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.agent.mapper.AsRolePremissionMapper;
import com.agent.pojo.AsRolePremission;
import com.agent.pojo.AsRolePremissionExample;
import com.agent.service.AsRolePremissionService;
@Service
public class AsRolePremissionServiceImpl implements AsRolePremissionService {
	@Autowired
	private AsRolePremissionMapper asRolePremissionMapper;
	
	@Override
	public List<Long> queryRolePremission(long roleid) {
		// TODO Auto-generated method stub
		List<Long> list=new ArrayList<Long>();
		AsRolePremissionExample example=new AsRolePremissionExample();
		example.createCriteria().andRoleidEqualTo(roleid);
		List<AsRolePremission> premissions=asRolePremissionMapper.selectByExample(example);
		for (AsRolePremission premission : premissions) {
			list.add(premission.getFunctionid());
		}
		return list;
	}

	@Override
	public void deleteRolePremission(Long roleid) {
		// TODO Auto-generated method stub
		AsRolePremissionExample example=new AsRolePremissionExample();
		example.createCriteria().andRoleidEqualTo(roleid);
		asRolePremissionMapper.deleteByExample(example);
	}

	@Override
	public void updateRolePremission(Long roleid, String usercode, String[] fids) {
		// TODO Auto-generated method stub
		deleteRolePremission(roleid);
		for (String id : fids) {
			AsRolePremission premission=new AsRolePremission();
			premission.setFunctionid(Long.parseLong(id));
			premission.setRoleid(roleid);
			premission.setCreatedby(usercode);
			premission.setCreationtime(new Date());
			asRolePremissionMapper.insertSelective(premission);
		}
	}
}
